<template>
  <div class="app-container">
      <el-form ref="form" :model="form" :rules="rules" >
      <el-form-item label="编号" prop="number">
        <el-input  v-model="form.numberNum" disabled style="width: 280px;"/>
      </el-form-item>
      <el-form-item label="用印事由" prop="stampReason">
        <el-input :disabled='isdisabled' v-model="form.stampReason" type="textarea" placeholder="请输入内容" />
      </el-form-item>
      <el-form-item label="公司名称" prop="companyName">
        <el-input style="width: 280px;" v-model="form.companyName" :disabled='isdisabled' placeholder="请输入公司名称" />
      </el-form-item>
      <el-form-item label="印章类型" prop="stampType">
        <el-select style="width: 280px;" v-model="form.stampType" placeholder="请选择印章类型" :disabled='isdisabled'>
          <el-option
            v-for="dict in dict.type.stamp_type"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="文件名称" prop="fileName">
        <el-input v-model="form.fileName" style="width: 280px;" :disabled='isdisabled' placeholder="请输入文件名称" />
      </el-form-item>
      <el-form-item label="文件份数" prop="fileCount">
        <el-input v-model="form.fileCount" style="width: 280px;" :disabled='isdisabled' placeholder="请输入文件份数" />
      </el-form-item>
      <el-form-item label="用印日期" prop="stampDate">
        <el-date-picker clearable style="width: 280px;"
                        v-model="form.stampDate"
                        type="date"
                        format="yyyy-MM-dd"
                        :disabled='isdisabled'
                        value-format="yyyy-MM-dd"
                        placeholder="请选择用印日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="是否外带" prop="isOutside">
        <el-select style="width: 280px;" v-model="form.isOutside" placeholder="请选择是否外带" :disabled='isdisabled'>
          <el-option
            v-for="dict in dict.type.export_is_type"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="备注" prop="remarks">
        <el-input :disabled='isdisabled' v-model="form.remarks" type="textarea" placeholder="请输入内容" />
      </el-form-item>
      <el-form-item label="附件">
        <file-upload v-model="form.attachment" :is-disabled='isdisabled'/>
      </el-form-item>
    </el-form>
      <div v-show="parentTaskId==null" class="dialog-footer" style="text-align:center">
          <el-button :loading="buttonLoading" size="small" type="info" @click="submitCallback">关闭</el-button>
          <el-button :loading="buttonLoading" size="small" type="primary" @click="submitForm" v-if="confirmVisible">提交</el-button>
      </div>
      <!-- 工作流开始 -->
      <verify ref="verifyRef" :taskId="taskId"
              :componentName="componentName"
              @submitCallback="submitCallback"
              :taskVariables="taskVariables" :sendMessage="sendMessage"></verify>
  </div>
</template>

<script>
import { getAdminStamp } from "@/api/oa/adminStamp";
import verify from "@/components/Process/Verify";
import {parseTime} from "@/utils/ruoyi";
export default {
  name: "AdminStampForm",
  dicts: ['export_is_type', 'stamp_type'],
  components: {
      verify
  },
  props: {
      businessKey: String, // 业务唯一标识
      parentTaskId: String, // 父级任务id
      taskId: String, // 任务id
      confirmVisible:{
          type: Boolean,
          default: true
      }
  },
  data() {
    return {
      componentName:"合同用印申请",
      isdisabled:true,
      // 按钮loading
      buttonLoading: false,
      // 遮罩层
      loading: true,
      // 表单参数
      form: {},
        projectNameList:[],
      // 表单校验
      rules: {
        stampReason: [
          { required: true, message: "用印事由不能为空", trigger: "blur" }
        ],
        companyName: [
          { required: true, message: "公司名称不能为空", trigger: "blur" }
        ],
        stampType: [
          { required: true, message: "印章类型不能为空", trigger: "change" }
        ],
        fileName: [
          { required: true, message: "文件名称不能为空", trigger: "blur" }
        ],
        fileCount: [
          { required: true, message: "文件份数不能为空", trigger: "blur" }
        ],
        stampDate: [
          { required: true, message: "用印日期不能为空", trigger: "blur" }
        ],
        isOutside: [
          { required: true, message: "是否外带不能为空", trigger: "change" }
        ],
      },
        taskVariables: undefined,
        //消息提醒
        sendMessage: {},
        processKey: 'oa_admin_stamp',
    };
  },
  watch: {
      businessKey: {
          immediate: true, // 很重要！！！
          handler (newVal) {
              if(newVal) {
                  this.getById()
              }
          }
      }
  },
  methods: {
    submitCallback(){
        this.$emit("closeForm")
    },
    async getById() {
      const {data} = await getAdminStamp(this.businessKey)
      this.form = data;
      if (data.actBusinessStatus.createTime){
            this.form.numberNum=this.processKey + '@' + parseTime(data.actBusinessStatus.createTime, '{y}{m}{d}{h}{i}{s}')
        }
    },
    /** 提交按钮 */
    submitForm() {
        getAdminStamp(this.businessKey).then(response => {
            this.taskVariables = {
                entity: response.data,
            };
            this.sendMessage = {
              title:'合同用印提醒',
                messageContent:this.$store.state.user.nickName + "审批通过了合同用印审批"
            }
        });
        this.$refs.verifyRef.visible = true
        this.$refs.verifyRef.reset()
    },
  }
};
</script>
<style scoped>
    /* 设置滚动条宽度和高度 */
    ::v-deep .el-table__body-wrapper::-webkit-scrollbar {
        width: 8px; /* 横向滚动条 */
        height: 8px; /* 纵向滚动条 必写 */
    }
    /* 设置滚动条样式 */
    ::v-deep .el-table__body-wrapper::-webkit-scrollbar-thumb {
        background-color: #dde;
        border-radius: 3px;
    }
    #selectForm >>> .el-form-item__label {
        font-size: 12px;
    }
    ::v-deep .bjsm .el-form-item__content{
        width: calc(100% - 130px) !important;
    }
</style>
